// packageA/pages/kaihei1/kaihei1.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
apiimg: app.apiimg,
gglist:'',
gglist1:'',
name:'',
list:[
  '胜率高','被邀次数多','游戏等级高','被拉黑数少'
],
type:0,
type1:0,
navlist1:[
  '不限','男','女'
],
saixuan:false,
navlist2: [{
  id: "1",
  title: "已收藏",
  xz_flag: false
},
{
  id: "2",
  title: "同城",
  xz_flag: false
},
{
  id: "3",
  title: "开黑过",
  xz_flag: false
},
{
  id: "4",
  title: "可开黑",
  xz_flag: false
},
{
  id: "5",
  title: "皇冠会员",
  xz_flag: false
}
],
page_no:1,
xiaoxi:0,
xiaoxi2:0,
  },
  z_fangda(e){
    let _this = this
    wx.previewImage({
      current: e.currentTarget.dataset.image, // 当前显示图片的http链接
      urls: _this.data.list3[e.currentTarget.dataset.parent].images
    })
  },
  z_open(){
    this.setData({
      saixuan:true
    })
  },
  z_close(){
    let navlist2 = [{
      id: "1",
      title: "已收藏",
      xz_flag: false
    },
    {
      id: "2",
      title: "同城",
      xz_flag: false
    },
    {
      id: "3",
      title: "开黑过",
      xz_flag: false
    },{
      id: "4",
      title: "可开黑",
      xz_flag: false
    },
    {
      id: "5",
      title: "皇冠会员",
      xz_flag: false
    }
    ]
    this.setData({
      type:0,
      type1:0,
      navlist2:navlist2
    })
  },
  z_wancheng(){
    this.setData({
      saixuan:false
    })
    this.z_jilu()
  },
  z_sea(e){
    this.setData({
      name:e.detail.value
    })
  },
  z_jiangpin(){
    this.z_jilu()
  },
  z_shaixuan1(e){
    this.setData({
      type:e.currentTarget.dataset.index + 1
    })
    this.z_jilu()
  },
  z_shaixuan2(e){
    this.setData({
      type1:e.currentTarget.dataset.index + 1
    })
  },
  z_shaixuan3: function (e) {
    let _this = this
    let index = e.currentTarget.dataset.index
    let xz_flag = e.currentTarget.dataset.xz_flag
    let id = e.currentTarget.dataset.id
    // if(index == '1'){
    //   if(wx.getStorageSync("dizhi") == 'true'){
    //     wx.authorize({
    //       scope: 'scope.userFuzzyLocation',
    //       success(res) {
    //           console.log(res)
    //           if(res.errMsg == 'authorize:ok'){
    //               wx.getFuzzyLocation({
    //                   type: 'wgs84',
    //                   success(res) {
    //                       console.log(res)  //此时里面有经纬度
    //                       const latitude = res.latitude
    //                       const longitude = res.longitude
    //                   }
    //               })
    //           }
    //       },
    //       fail(err) {
    //           console.log(err)   
    //       }                    
    //   })
    //     wx.setStorageSync("dizhi", 'true')
    //   }
    // }
    if (xz_flag) {
      _this.setData({
        [`navlist2[${index}].xz_flag`]: false,
      })
    } else {
      _this.setData({
        [`navlist2[${index}].xz_flag`]: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_yonghu()
    this.z_jilu()
    // this.z_jilu2()
    this.z_jilu3()
    this.z_peizhi()
    this.xcx_msg_info1()
  },
  z_shuaxin(){
    this.setData({
      list3:[]
    })
    this.z_jilu()
    this.z_jilu3()
  },
  xcx_msg_info1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/totalNoReadNum',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          xiaoxi:res.data.data.total_num
        })
      }
    })
  },
  z_peizhi() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          peizhi: res.data.data
        })
      }
    })
  },
  z_jilu3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/config/unprizeList?fbwz_type=4',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          mylist:res.data.data
        })
      }
    })
   },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
         _this.guanggao2()
         _this.guanggao3()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=14',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  guanggao3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=15',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist1:res.data.data[0]
         })
      }
    })
  },
  z_jilu2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/lotteryRecord?page_no=1&page_num=10&type=2',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list2:res.data.data.list
         })
      }
    })
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
       if(res.data.code == '1001'){
         _this.setData({
           login:true,
           yonghu:res.data.data
         })
       }
      }
    })
  },
  z_jilu(){
    let _this = this
    let order_type = _this.data.type
    if(order_type > 0){
      order_type = order_type - 1
    }
    let sex = ''
    if(_this.data.type1 == 1){
      sex = '不限'
    } else if(_this.data.type1 == 2){
      sex = '男'
    } else if(_this.data.type1 == 3){
      sex = '女'
    }
    let sx_ysc = ''
    if(_this.data.navlist2[0].xz_flag == true){
      sx_ysc = '1'
    }
    let sx_tc = ''
    if(_this.data.navlist2[1].xz_flag == true){
      sx_tc = '1'
    }
    let sx_khg = ''
    if(_this.data.navlist2[2].xz_flag == true){
      sx_khg = '1'
    }
    let sx_kkh = ''
    if(_this.data.navlist2[3].xz_flag == true){
      sx_kkh = '1'
    }
    let sx_hg = ''
    if(_this.data.navlist2[4].xz_flag == true){
      sx_hg = '1'
    }
    let params = {
      "token":wx.getStorageSync("user_token"),
      "page_no":_this.data.page_no,
      "page_num":"10",
      "name":_this.data.name,
      "order_type": order_type,
      "sex":sex,
      "sx_ysc":sx_ysc,
      "sx_tc":sx_tc,
      "sx_khg":sx_khg,
      "sx_kkh":sx_kkh,
      "sx_hg":sx_hg
    }
    wx.request({
      url: app.apiurl + 'api/member/yqMemberKhList',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list3:res.data.data.list
         })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 //下滑刷新
//  let _this = this
//  let page_no  = _this.data.page_no
//  page_no = page_no+1
//  _this.setData({
//    page_no:page_no
//  })
//  _this.z_jilu()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})